/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package linkeddata.arida.ufc.br.servlet;

import com.google.gson.Gson;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import linkeddata.arida.ufc.br.endpoints.GetPredicates;
import linkeddata.arida.ufc.br.endpoints.LoadFileUrl;

/**
 *
 * @author jeovane
 */
public class SourcesPredicatesServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String prefixes = request.getParameter("prefixes");
        Map<String, String> mapSources = new LinkedHashMap<String, String>();

        LoadFileUrl load = new LoadFileUrl(prefixes);
        GetPredicates predicates = new GetPredicates(load);
        
        try {
            mapSources = predicates.mapSources();
        } catch (Exception ex) {
            System.out.println("ERRO: " + ex.getMessage());
        }
        
        String mSources = new Gson().toJson(mapSources);
        
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(mSources);
    }
}
